package com.css.apps.base.user.action.report;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.css.apps.base.common.Constants;
import com.css.apps.base.common.util.ExportExcelUtil;
import com.css.apps.base.user.service.UserCountGraphService;
import com.css.webbase.webwork.action.UserAction;

@SuppressWarnings("serial")
public class UserStatusCountExport extends UserAction {
	
	private int year;
	
	@Override
	protected String userGo() {
		if (year == 0) {
			year = Calendar.getInstance().get(Calendar.YEAR);
		}
		String headerKey = "总部用户状态统计表", subKey = "下属企业用户状态统计表";
		Map<String, List<Object[]>> dataMap = new HashMap<>();
		Map<String, List<String>> headMap = new HashMap<>(), typeMap = new HashMap<>();
		Map<String, List<Integer>> widthMap = new HashMap<>();
		
		UserCountGraphService service = new UserCountGraphService();
		List<Object[]> headerData = service.getHeaderUserStatusCountTabData(),
				subData = service.getSubOrgUserStatusCountTabData(),
				_hData = new ArrayList<>(), _sData = new ArrayList<>();
		Object[] _hd = new Object[2], _sd = new Object[2];
		for (int i = 0; i < 2; i++) {
			Object[] hd = headerData.get(i);
			if (Constants.YES.equals((String) hd[1])) {
				_hd[0] = hd[0];
			} else {
				_hd[1] = hd[0];
			}
			Object[] sd = subData.get(i);
			if (Constants.YES.equals((String) sd[1])) {
				_sd[0] = sd[0];
			} else {
				_sd[1] = sd[0];
			}
		}
		_hData.add(_hd);
		_sData.add(_sd);
		dataMap.put(headerKey, _hData);
		dataMap.put(subKey, _sData);
		
		List<String> headList = new ArrayList<String>();
		headList.add("使用中");
		headList.add("停用");
		headMap.put(headerKey, headList);
		headMap.put(subKey, headList);
		
		//0数字   1字符组     2日期          字典
		List<String> typeList = new ArrayList<String>();
		typeList.add("0");
		typeList.add("0");
		typeMap.put(headerKey, typeList);
		typeMap.put(subKey, typeList);
		
		List<Integer> widthList = new ArrayList<Integer>();
		widthList.add(3000);
		widthList.add(3000);
		widthMap.put(headerKey, widthList);
		widthMap.put(subKey, widthList);
		
		ExportExcelUtil.exportExcel(year + "年用户状态统计.xls", dataMap, headMap, typeMap, widthMap);
		return null;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

}
